#!/bin/sh
#注意需要提交tag才执行这个文件，每个版本执行一次


# path=../

echo -e "\033[32m start git \033[0m"

cd ..

echo -e "\033[32m start pull  \033[0m" 

git pull

if [[ "$?" != 0 ]];then
 echo -e "\033[41m pull fail \033[0m" 
 cmd /k dir
fi

git status

result=$(git status | grep clean)

if [[ "$result" != "" ]]; then
  cmd /k dir
fi

tag=''
read -p "请输入tag版本号：" tag

if [[ "$tag" == '' ]];then
 echo -e "\033[41m tag can not be empty \033[0m" 
 cmd /k dir
fi

echo -e "\033[32m start add \033[0m"

git add .

commit=''
if [[ "$#" > 0 ]];then
 commit=$1
else 
 read -p "请输入本次提交信息：" commit
fi

git commit -m "$commit"


if [[ "$?" != 0 ]];then
 echo -e "\033[41m commit fail \033[0m" 
 cmd /k dir
fi

git tag -a $tag -m $tag

git push

if [[ "$?" != 0 ]];then
 echo -e "\033[41m push fail \033[0m"
 cmd /k dir
fi

git push origin tag $tag

echo -e "\033[32m push success \033[0m"



# 阻止关掉窗口
cmd /k dir